﻿using System;
using System.Collections.Generic;
using System.Data;

/*
 * MANIPULAÇÃO DO XML
 */
namespace TowerDefense_MLP
{
    public class MapsDataBase
    {
        private static DataRow GetDataRow(int mapID)
        {
            DataSet dataBase = new DataSet();
            dataBase.ReadXml("MapDataBase.xml");
            return dataBase.Tables["Maps"].Select(" ID = '" + mapID.ToString() + "'")[0];
        }

        public static string GetImagePath(int mapID)
        {
            DataRow dRow = GetDataRow(mapID);
            return Convert.ToString(dRow["ImagePath"]);
        }

        public static string GetImageCodePath(int mapID)
        {
            DataRow dRow = GetDataRow(mapID);
            return Convert.ToString(dRow["ImageCodePath"]);
        }

        // wave[i][0] = id do inimigo
        // wave[i][1] = qtd de inimigos na wave
        public static List<int[]> GetWavesInfos(int mapID)
        {
            DataRow dRow = GetDataRow(mapID);
            string[] enemies = Convert.ToString(dRow["Enemies"]).Split('/');
            string[] wave;
            List<int[]> wavesAux = new List<int[]>();

            foreach (string waveInfo in enemies) 
            {
                wave = waveInfo.Split('-');
                wavesAux.Add( new int[]{ Convert.ToInt32(wave[0]), Convert.ToInt32(wave[1]) } );
            }

            return wavesAux;
        }
    }
}
